package OddMuse;

=head1 NAME

OddMuse::Database::Backlinks - Perl Module for OddMuse backlink display

=head1 DESCRIPTION

This module renders the returned backlink hash into html.

=cut

$VERSION = ( q$Revision: 31 $ ) =~ /(\d+)/g;
use strict;

=head1 SYNOPSIS

Call function directly somwhere in your code.  Here are two examples.

 sub PrintMyContent {
     GetBackLink( $_[0] );
 }

You can also modify the OddMuse footer to achieve a similar result.

 *OldPrintFooter = *PrintFooter;
 *PrintFooter = *BacklinksPrintFooter;

 sub BacklinksPrintFooter {
     my ( $id, $rev, $comment ) = @_;
     GetBackLink( $id );
     OldBacklinksPrintFooter( @_ );
 }

=head1 FUNCTIONS

=over 4

=item * GetBackLink

This function creates a reference to the OddMuse::Database->fetch_backlinks
method and then parses through the returned data in the hash into html links.
Then the links are stuffed into an array, where they can be further formatted
for correct display.  Finally, function outputs a header and the list of
backlinks.

See: L<OddMuse::Database>

=cut

sub GetBackLink {
    my ( @backlinks, @unpopped, @alldone );
    my $id = shift;

    use vars qw($BacklinkBanned);
    $BacklinkBanned = "HomePage|ScratchPad" if !$BacklinkBanned;

    my $backlinks =
      OddMuse::Database->fetch_backlinks( $id );    # Fetch Back Links

    # Render backlinks into html links
    while ( my ( $backlink, $attribute ) = each %{ $backlinks } ) {
        if ( $attribute->{ 'wikiname' } !~ /^($BacklinkBanned)$/ ) {
            push( @unpopped,
                  ScriptLink( UrlEncode( $attribute->{ 'wikiname' } ),
                              $attribute->{ 'title' },
                              ' local backlink',
                              undef,
                              T( 'Internal Page: ' . $attribute->{ 'title' } )
                            )
                );
        } ## end if ( $attribute->{ 'wikiname'...
    } ## end while ( my ( $backlink, $attribute...

    my $arraycount = @unpopped;
    return if !$arraycount;    # Dont bother with the rest if empty results

    # Pop and Push data to make it look good (no trailing commas)
    my $temp = pop( @unpopped );
    foreach my $backlink ( @unpopped ) {
        push( @alldone, $backlink . ", " );
    }
    push( @alldone, $temp );    # And push last entry back in
    print $q->div( { -class => 'docmeta' },
                   $q->h2( T( 'Pages that link to this page' ) ), @alldone );
} ## end sub GetBackLink

1;
__END__

=back

=head1 CSS

=over 4

=item * h2.docmeta

The specific h2 header that prefixes the backlinks.

=item * a.backlink

Each backlink returned has this class assigned to it.

=back

=head1 BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests to C<cmauch@gmail.com>

=head1 AUTHOR

Charles Mauch <cmauch@gmail.com>

=head1 LICENSE

Copyright (c) 2006 Charles Mauch

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA  02110-1301, USA.

=head1 SEE ALSO

perl(1).
OddMuse::Database(1).

=cut

# $Id: Backlinks.pm 31 2006-09-29 06:21:37Z cmauch $
